#include <iostream>
#include <string>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    
    int cnt5 = 0;
    for (int i=0;i<n;i++) {
        if (s[i] == '5') cnt5++;
    }
    int ans = 0;
    for (int i = 0; i < cnt5; i++) {
        if (s[i] == '2') ans++;
    }
    
    cout << ans << endl;
    return 0;
}